package com.farewell.service.impl;

import com.farewell.dao.OrderDao;
import com.farewell.pojo.Order;
import com.farewell.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author Farewell
 * @date 2021/3/25
 */
@Service("OrderService")
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderDao orderDao;

    @Override
    public List<Order> findAll() {
        List<Order> orderList = orderDao.findAll();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        for (Order order : orderList) {
            order.setOrderTimeStr(sdf.format(order.getOrderTime()));
            if (order.getOrderStatus()) {
                order.setOrderStatusStr("已支付");
            }else {
                order.setOrderStatusStr("待支付");
            }
        }
        return orderList;
    }

    @Override
    public void save(Order order) {
        orderDao.save(order);
    }

    @Override
    public void update(Order order) {
        orderDao.update(order);
    }

    @Override
    public void delete(String id) {
        orderDao.delete(id);
    }
}
